<?php
namespace app\api\controller;

use  think\Controller;
use app\api\model\User as UserModel;
use think\Db;
use think\facade\Cache;
class User extends Controller
{   
    //使用token
    public function token(){
        echo md5('cb'.'cypt'.time());
    }
    //登录拦截
    public function test($token=""){
        if($token==Cache::get('token')){
            $user=UserModel::select();
            json(200,'成功',$user);
        }else{
            json(-1,'请先登录',);
        }

    }

    public function index(){
        $user=UserModel::select();
        json(200,'成功',$user);

    }


    public function doadd(){

        $data=$this->request->param();
        $model = new UserModel();
        $res = $model->save($data);
        if($res){
            json(200,'成功',$res);
        }
        else{
            json(200,'失败');
        }
    }

}